package tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.Date;

import org.junit.Before;
import org.junit.Test;

import papers.Review;
import users.Reviewer;

/**
 * Tests the methods in the review class
 * @author Dickson Kwong
 */

public class TestReview {
	
	/**
	 * The review
	 */
	private Review my_review;
	
	/**
	 * The reviewer
	 */
	private Reviewer my_reviewer;
	
	/**
	 * The reviewer name
	 */
	private String reviewer_name = "Testing_reviewer";
	
	/**
	 * The date
	 */
	private Date my_date = new Date();
	
	/**
	 * The review file
	 */
	private File my_reviewFile = new File("Review.txt");
	
	
	/**
	 * Initializes the review
	 */
	@Before
	public void setUp() {
		my_reviewer = new Reviewer(reviewer_name);
		
		my_review = new Review(my_reviewer, my_date, my_reviewFile);

	}
	
	/**
	 * Tests the create review method
	 */
	@Test
	public void testCreateReview() {
		assertEquals("Reviewer is not the same", 
				my_review.getUser(), my_reviewer);
		assertEquals("Submission date is not the same", 
				my_review.getSubmissionDate(), my_date);
		assertEquals("Review file is not the same", 
				my_review.getReview(), my_reviewFile);
	}
	
	/**
	 * Tests the set review method
	 * Check the date diff. by delay 0.001s
	 */
	@Test
	public void testSetReview() {
		
		try {
			Thread.sleep(1);  
	 	}catch (InterruptedException ie) {
			System.out.println(ie.getMessage());
		}
		
		File newReview = new File("newReview.txt");
		my_review.setReview(newReview);
		
		assertEquals("Reviewer is not the same", 
				my_review.getUser(), my_reviewer);
		assertTrue("New date is not after old date",
				my_review.getSubmissionDate().after(my_date));

		assertEquals("Review file is not the same", 
				my_review.getReview(), newReview);
		
	}

}
